<template>
  <div class="header">
    <div class="header-left iconfont">&#xe624;</div>
    <input type="search"
           class="header-input"
           placeholder='搜索城市/景点/游玩主题'>
    <router-link to="/city">
      <div class="header-right iconfont">{{ this.city }}&#xe62d;</div>
    </router-link>
  </div>
</template>

<script>
import { mapState } from 'vuex'
// 辅助函数，把vuex中的数据映射到组件的计算属性里，不用重复书写多余代码
export default {
  name: "HomeHeader",
  computed: {
    ...mapState(['city'])
    // 把vuex中的city映射到计算属性的city之中，必须计算属性与state中的数据同名，city：{。。。}
  }
};
</script>

<style lang="stylus" scoped>
@font-face {
  font-family: 'iconfont';
  src: url('~@/assets/style/iconfont/iconfont.woff2?t=1636704678087') format('woff2'), url('~@/assets/style/iconfont/iconfont.woff?t=1636704678087') format('woff'), url('~@/assets/style/iconfont/iconfont.ttf?t=1636704678087') format('truetype');
}

.iconfont {
  font-family: 'iconfont' !important;
  font-size: 16px;
  font-style: normal;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.header {
  display: flex;
  height: 0.86rem;
  line-height: 0.86rem;
  background: #00bcd4;
  color: #fff;

  .header-left {
    width: 0.64rem;
    float: left;
    text-align: center;
  }

  .header-right {
    // 设置段落的最小宽度：，防止城市字数不同导致布局变动
    min-width: 1.04rem;
    padding: 0 0.1rem;
    float: right;
    text-align: center;
    color: white;
  }

  .header-input {
    flex: 1;
    background: #fff;
    border-radius: 0.1rem;
    margin-top: 0.12rem;
    height: 0.64rem;
    margin-left: 0.2rem;
    padding-left: 0.2rem;
    line-height: 0.64rem;
    color: #ccc;
  }

  .searchitem {
    position: absolute;
  }
}
</style>